/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Indicator2Evaluate.java
 * Date: 17/11/2010
 */

package com.ingenius.sau.shared.model.core;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.FetchGroups;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.instruments.AssignedInstrument;

/**
 * Class <strong>Indicator2Evaluate</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroups({
		@FetchGroup(name = "with_feature", members = { @Persistent(name = "feature2Evaluate") }),
		@FetchGroup(name = "with_instruments", members = { @Persistent(name = "assignedInstruments") }) })
public class Indicator2Evaluate implements BaseBean {

	// DATA
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String description;

	@Persistent(nullValue = NullValue.NONE)
	private float weighing;

	@Persistent(nullValue = NullValue.NONE)
	private String justify;

	@Persistent
	private float grade;

	@Persistent
	private Feature2Evaluate feature2Evaluate;

	@Persistent(mappedBy = "indicator2Evaluate")
	@Element(dependent = "true")
	private List<AssignedInstrument> assignedInstruments;

	// CONSTRUCTORS

	public Indicator2Evaluate() {
	}

	public Indicator2Evaluate(String id) {
		this.id = id;
	}

	// METHODS
	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public float getWeighing() {
		return weighing;
	}

	public void setWeighing(float weighing) {
		this.weighing = weighing;
	}

	public String getJustify() {
		return justify;
	}

	public void setJustify(String justify) {
		this.justify = justify;
	}

	public float getGrade() {
		return grade;
	}

	public void setGrade(float grade) {
		this.grade = grade;
	}

	public Feature2Evaluate getFeature2Evaluate() {
		return feature2Evaluate;
	}

	public void setFeature2Evaluate(Feature2Evaluate feature2Evaluate) {
		this.feature2Evaluate = feature2Evaluate;
	}

	public List<AssignedInstrument> getAssignedInstruments() {
		return (assignedInstruments == null) ? assignedInstruments = new ArrayList<AssignedInstrument>()
				: assignedInstruments;
	}

	public void setAssignedInstruments(
			List<AssignedInstrument> assignedInstruments) {

		this.assignedInstruments = assignedInstruments;
	}

	public void addAssignedInstrument(AssignedInstrument assignedInstrument) {
		getAssignedInstruments().add(assignedInstrument);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Indicator2Evaluate) {
			return ((Indicator2Evaluate) obj).getId().equals(id);
		}
		return false;
	}

	public Indicator2Evaluate toDTO() {
		if (this != null) {
			this.setAssignedInstruments(null);
		}
		return this;
	}

}
